#include "chap12.h"
#include <pthread.h>
#include <stdio.h>

int beers = 2000000;
pthread_mutex_t beers_lock = PTHREAD_MUTEX_INITIALIZER;

int main() {
	pthread_t threads[20];
	int t;
	printf("%d bottles of beer on the wall\n%d bootles of beer\n", beers, beers);
	for (t = 0; t < 20; t++) {
		if (pthread_create(&threads[t], NULL, drink_lots, NULL) == -1) {
			char msg[32];
			sprintf(msg, "Can't create thread t%d", t);
			error(msg);
		}
	}

	void* result;
	for (t = 0; t < 20; t++) {
		if (pthread_join(threads[t], &result) == -1) {
			char msg[32];
			sprintf(msg, "Can't join thread t%d", t);
			error(msg);
		}
	}
	printf("There are now %d bottles of beer on the wall\n", beers);
	return 0;

}

